package com.blyat.xsoft.gateway.security;

import com.blyat.xsoft.gateway.context.ReactiveXSoftContextHolder;
import org.springframework.security.authentication.ReactiveAuthenticationManager;
import org.springframework.security.web.server.authentication.AuthenticationWebFilter;
import org.springframework.web.server.ServerWebExchange;
import org.springframework.web.server.WebFilterChain;
import reactor.core.publisher.Mono;

/**
 * @Auther: syh
 * @Date: 2020/9/10
 * @Description:
 */
public class XSoftAuthenticationWebFilter extends AuthenticationWebFilter {
    public XSoftAuthenticationWebFilter(ReactiveAuthenticationManager authenticationManager) {
        super(authenticationManager);
    }

    @Override
    public Mono<Void> filter(ServerWebExchange exchange, WebFilterChain chain) {
        return super.filter(exchange, chain).subscriberContext( // 这里保存上下文中的exchange
                ReactiveXSoftContextHolder.withXSoftContext(ServerWebExchange.class, Mono.just(exchange)));
    }
}
